package cn.sitia.wallet.controller;

import cn.sitia.wallet.domain.WalletTransaction;
import cn.sitia.wallet.service.IUserWalletService;
import cn.sitia.wallet.service.IWalletTransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@CrossOrigin
public class WalletController {
    @Autowired
    private IUserWalletService userWalletService;
    @Autowired
    private IWalletTransactionService walletTransactionService;

    @GetMapping("/getUserBalance/{userId}")
    //获取账户余额
    private BigDecimal getUserBalance(@PathVariable Integer userId) {
        return userWalletService.getUserWalletBalance(userId);
    }

    @RequestMapping("/purchase")
    private void purchase(@RequestParam BigDecimal amount) {
        userWalletService.purchase(amount);
    }

    @RequestMapping("/refund")
    public void refund(@RequestParam BigDecimal amount) {
        userWalletService.refund(amount);
    }

    @GetMapping("/getWalletTransactionHistory")
    public List<WalletTransaction> getWalletTransactionHistory(@RequestParam Integer userId) {
        return walletTransactionService.getWalletTransactionHistory(userId);
    }
}
